package com.sf.proxy.custom.dynamic.jdkcustom;


import com.sf.proxy.custom.dynamic.jdkcustom.proxy.SFClassLoader;
import com.sf.proxy.custom.dynamic.jdkcustom.proxy.SFInvocationHandler;
import com.sf.proxy.custom.dynamic.jdkcustom.proxy.SFProxy;

import java.lang.reflect.Method;

/**
 *  基于 JDK 实现
 *  媒婆
 */
public class MeiPoProxy implements SFInvocationHandler {

    private Male male;

    public void setObject(Male male) {
        this.male = male;
    }

    public Object getProxy(){
        return SFProxy.newProxyInstance(new SFClassLoader(),male.getClass().getInterfaces(),this);
    }


    private void before(){
        System.out.println("先确认下,你喜欢上面类型的");
    }
    private void after(){
        System.out.println("满意不?");
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(male, args);
        after();
        return invoke;
    }
}
